<template>
  <el-table :data="get_cateList" border style="width: 100%" row-key="id" default-expand-all>
    <el-table-column prop="pid" label="分类编号" width="180"></el-table-column>
    <el-table-column prop="catename" label="分类名称" width="180"></el-table-column>
    <el-table-column prop="img" label="图片">
       <template v-slot="item">
         <img :src="$baseUrl+item.row.img" alt="" class="img">
       </template>
    </el-table-column>
    <el-table-column prop="status" label="状态">
        <template v-slot="item">
          <el-button type="primary" plain size="small" v-if="item.row.status == 1">启用</el-button>
          <el-button type="danger" plain size="small" v-else>禁用</el-button>
        </template>
      </el-table-column>
    <el-table-column  label="操作">
        <template v-slot="item">
          <el-button type="primary" size="small" @click="edit(item.row.id)">编辑</el-button>
        <el-button type="danger" size="small" @click="delItem(item.row.id)">删除</el-button>
        </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { mapGetters,mapActions } from 'vuex';
import {catedelete} from "@/request/api.js"
export default {
  data() {
    return {
     
    };
  },
  computed:{
    ...mapGetters({
      get_cateList:"cate/get_cateList"
    })
  },
  methods:{
    ...mapActions({
      action_cateList:"cate/action_cateList"
    }),
    //编辑
    edit(id){
      this.$emit("edit",id);
    },
    //删除
    delItem(id){
      this.$confirm("是否删除该商品分类", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          try {
            let res = await catedelete({ id });
            if (res.code == 200) {
              //提示，更新数据（重新请求数据）
              this.$message.success(res.msg);
              this.action_cateList();
            } else {
              this.$message.info(res.msg);
            }
          } catch (err) {
            this.$message.error(err);
          }
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    }
  },  
  mounted(){
    //请求数据
    this.action_cateList();
  }
};
</script>

<style scoped>
.img{
  width: 200px;
}
</style>